package com.yeung.swordoffer;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int result = interBreakProblem(n);
        System.out.println(result);
    }
    public static int interBreakProblem(int n) {

        if(n==2 || n==3)
            return n-1;
        if(n==4) return n;
        int result=1;
        while(n>4) {
            result*=3;
            n-=3;
        }

        return result*n;

    }
}